<?php

// phpMyRealty 3
//
// File Name: ajaxFavorites.php
// File Location : ./includes/
//
// Copyright (c)2009 phpMyRealty.com
//
// e-mail: support@phpMyRealty.com

// Include xajax class
include( PATH . '/includes/xajax/xajax_core/xajax.inc.php'); 

// Start new xajax
$xajax = new xajax();

// Set the correct PATH to the xajax libraries
$xajax->configure('javascript URI', URL . '/includes/xajax/');
//$xajax->configure('debug', true);

// ----------------------------------------------------------------------------
// favorites($arg)
//
// xajax function to add the listing into the favorites list
// $arg - selected listing id
//
function favorites($arg) {

 global $db;
 global $lang;

 // Check the returned variable, set to 0 if incorrect
 if (!eregi('^[0-9]+$', $arg) && $arg != 'ANY') $arg = '0';

 // Instantiate the xajaxResponse object
 $objResponse = new xajaxResponse();
    
 // add a command to the response to assign the innerHTML attribute of
 // the element with id="SomeElementId" to whatever the new content is
 $tag_name = 'favorites-' . $arg;

 favoriteListingsAdd($arg);

 $objResponse->assign($tag_name,"innerHTML", '<span style="cursor: pointer; display: block;" class="favorites" onclick="javascript:xajax_favorites_remove(\'' . $arg . '\');">' . $lang['Favorites_Remove'] . '</span>');
 
 //return the  xajaxResponse object
 return $objResponse;
  
}

// ----------------------------------------------------------------------------
// favorites_remove($arg)
//
// xajax function to remove the listing from the favorites list
// $arg - selected listing id
//
function favorites_remove($arg) {

 global $db;
 global $lang;

 // Check the returned variable, set to 0 if incorrect
 if (!eregi('^[0-9]+$', $arg) && $arg != 'ANY') $arg = '0';

 // Instantiate the xajaxResponse object
 $objResponse = new xajaxResponse();
    
 // add a command to the response to assign the innerHTML attribute of
 // the element with id="SomeElementId" to whatever the new content is
 $tag_name = 'favorites-' . $arg;

 favoriteListingsRemove($arg);

 $objResponse->assign($tag_name,"innerHTML", '<span style="cursor: pointer; display: block;" class="favorites" onclick="javascript:xajax_favorites(\'' . $arg . '\');">' . $lang['Favorites_Add'] . '</span>');
 
 //return the  xajaxResponse object
 return $objResponse;
  
}

// Register xajax functions
$xajax->registerFunction('favorites');
$xajax->registerFunction('favorites_remove');

// Process the xajax request
$xajax->processRequest();

?>